/**
 *  到期剩余天数
 * @param {*} expireTime 到期时间
 * @param {*} serverTime 服务器时间戳
 * @returns
 */
export function getLeftDay(expireTime: string | number, serverTime: number) {
  if (!expireTime) {
    return 0;
  }
  if (typeof expireTime === "string") {
    expireTime = Math.floor(new Date(expireTime).getTime() / 1000);
  }
  if (expireTime <= serverTime) {
    return 0;
  } else {
    return Math.ceil((expireTime - serverTime) / (60 * 60 * 24));
  }
}
/**
 * 计算到期剩余时间
 */
export function getLeftTime(
  expireTime: number,
  serverTime: number,
  localTime: number
) {
  if (!expireTime || !serverTime || !localTime) {
    return 0;
  }
  const nowTime = Math.round(Date.now() / 1000);
  const serverNowTime = serverTime + (nowTime - localTime);
  return Math.max(0, Math.round(expireTime - serverNowTime));
}

/**
 * 格式化金钱 后台传过来的是分 转为元
 * @param {*} money
 */
export function formatMoney(money = 0) {
  return Number((money / 100).toFixed(2));
}

/**
 * 翻译币数量-适配多语言
 * 中日文返回: n万
 * 其他语言返回: nn,nnn
 * @param {*} money
 */
export function formatTsb(num = 0) {
  if (typeof num === "string") {
    num = Number(num);
  }
  if (typeof num !== "number") {
    return num;
  }
  if (num >= 10000) {
    return Number(Math.round(num / 10000).toFixed(2)) + "万";
  }
  const arr = num.toString().split("");
  const arr2 = [];
  while (arr.length) {
    if (arr2.length) {
      arr2.unshift(",");
    }
    arr2.unshift(arr.splice(-3).join(""));
  }
  return arr2.join("");
}
import wxImg from "@/assets/images/qr_wxq.png";
export function getWeChatImg() {
  return wxImg;
}
export const kefuUrl = "https://work.weixin.qq.com/kfid/kfc7e404633cf3962fb";
